// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 4/12/2007 09:13:59
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   RChoice.java

package utility;

import java.awt.*;
import java.util.Locale;

// Referenced classes of package de.escape.quincunx.i18n:
//            I18n, Localizable

public class RChoice extends Choice
    implements Localizable
{

    public RChoice()
    {
        localeUnknown = true;
        resTags = new String[0];
    }

    public void add(String tag)
    {
        addItem(tag);
    }

    public void addItem(String tag)
    {
        super.addItem(I18n.getString(tag, getLocale()));
        String newTags[] = new String[resTags.length + 1];
        if(resTags.length > 0)
            System.arraycopy(resTags, 0, newTags, 0, resTags.length);
        newTags[resTags.length] = tag;
        resTags = newTags;
    }

    public String getTag(int index)
    {
        return resTags[index];
    }

    public String getSelectedTag()
    {
        return resTags[getSelectedIndex()];
    }

    public void insert(String tag, int index)
    {
        super.insert(I18n.getString(tag, getLocale()), index);
        String newTags[] = new String[resTags.length + 1];
        if(index > 0)
            System.arraycopy(resTags, 0, newTags, 0, index);
        newTags[index] = tag;
        if(index < resTags.length)
            System.arraycopy(resTags, index, newTags, index + 1, resTags.length - index);
        resTags = newTags;
    }

    public void remove(int index)
    {
        super.remove(index);
        String newTags[] = new String[resTags.length - 1];
        if(index > 0)
            System.arraycopy(resTags, 0, newTags, 0, index);
        if(index < resTags.length - 1)
            System.arraycopy(resTags, index + 1, newTags, index, resTags.length - index - 1);
        resTags = newTags;
    }

    public void remove(String tag)
    {
        for(int i = 0; i < resTags.length; i++)
            if(resTags[i].equals(tag))
            {
                remove(i);
                return;
            }

    }

    public void removeAll()
    {
        super.removeAll();
        resTags = new String[0];
    }

    public void select(String tag)
    {
        for(int i = 0; i < resTags.length; i++)
            if(resTags[i].equals(tag))
            {
                select(i);
                return;
            }

    }

    public void setLocale(Locale l)
    {
        super.setLocale(l);
        setVisible(false);
        int selected = getSelectedIndex();
        for(int i = getItemCount() - 1; i >= 0; i--)
            super.remove(i);

        for(int t = 0; t < resTags.length; t++)
            super.addItem(I18n.getString(resTags[t], getLocale()));

        select(selected);
        setVisible(true);
        invalidate();
    }

    public Locale getLocale()
    {
        try
        {
            localeUnknown = false;
            return super.getLocale();
        }
        catch(IllegalComponentStateException _ex)
        {
            localeUnknown = true;
        }
        return null;
    }

    public void update(Graphics g)
    {
        if(localeUnknown)
            setLocale(getLocale());
        else
            super.update(g);
    }

    protected boolean localeUnknown;
    protected String resTags[];
}